var e = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), t = require("../../../@babel/runtime/helpers/asyncToGenerator"), a = require("../../../mycomponent/yz_pay/yz_pay"), r = getApp();

Page({
    behaviors: [ a ],
    data: {
        details: {},
        quantity: "",
        price: 0,
        buttons: []
    },
    onLoad: function(e) {
        this.getStream();
    },
    onReady: function() {},
    setPrice: function() {
        var e = this.data.quantity * this.data.details.stream_eq_money;
        this.setData({
            price: e
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        var e = getCurrentPages();
        e[e.length - 2].getBehavior(!0);
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getStream: function() {
        var e = this, t = r.getNetAddresss("plugin.new-media-advertising.frontend.stream.recharge-stream");
        r._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data;
                if (1 != a.result) return r.tips(a.msg);
                var n = a.data.buttons;
                n.forEach(function(e) {
                    3 == e.value ? e.class = "icon-balance_yue" : 55 == e.value && (e.class = "icon-balance_i");
                }), e.setData({
                    details: a.data,
                    buttons: n
                });
            }
        });
    },
    getPaySn: function(a) {
        var n = this;
        return t(e.default.mark(function t() {
            var s, i, u, o, c;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    if (s = a.currentTarget.dataset.item, i = s.value, !((u = n.data.quantity) <= 0)) {
                        e.next = 5;
                        break;
                    }
                    return e.abrupt("return", r.tips("充值数量需大于1"));

                  case 5:
                    if (o = r.getNetAddresss("plugin.new-media-advertising.frontend.stream.get-pay-sn"), 
                    1 != s.need_password) {
                        e.next = 11;
                        break;
                    }
                    return e.next = 9, n.getPayKeyboardPassword();

                  case 9:
                    c = e.sent, o += "&password=" + c;

                  case 11:
                    r._getNetWork({
                        url: o,
                        data: {
                            pay_type: i,
                            stream: u
                        },
                        success: function(e) {
                            var t = e.data;
                            if (1 != t.result) return 3 == i ? void n.verifyPasswordError(t) : r.tips(t.msg);
                            3 == i ? n.rechargePay(i, {}) : n.alipay(t.data.order_sn);
                        }
                    });

                  case 12:
                  case "end":
                    return e.stop();
                }
            }, t);
        }))();
    },
    alipay: function(e) {
        var t = this, a = r.getNetAddresss("plugin.new-media-advertising.frontend.stream.alipay");
        r._getNetWork({
            url: a,
            data: {
                order_sn: e
            },
            success: function(e) {
                var a = e.data;
                if (1 != a.result) return r.tips(a.msg);
                t.rechargePay(1, a);
            }
        });
    }
});